﻿var d;
var id_place;
function newTreeMap() {
    d = new dTree('d');
    d.add(0, -1, 'My ShopMap tree');
    d.add(1, 0, 'Hà Nội', 'javascript: mapHaNoi();', 'ShopMaps of Hà Nội', 'dtree/img/folder.gif', 'dtree/img/folder.gif');
    d.add(2, 0, 'Hải Dương', 'javascript: mapHaiDuong();', 'ShopMaps of Hải Dương', 'dtree/img/folder.gif', 'dtree/img/folder.gif');
    d.add(3, 0, 'Bắc Ninh', 'javascript: mapBacNinh();', 'ShopMaps of Hưng Yên', 'dtree/img/folder.gif', 'dtree/img/folder.gif');
    document.write(d);
}
function mapHaNoi() {
    if (map != null && id_place!= d.getSelected()) {
        map.destroy();
    }
    id_place = d.getSelected();
    setContentTable(id_place);
    document.getElementById('lienkute').innerText = "Bảng địa điểm TP.Hà Nội";
    init('Hà Nội', 'hanoi_rg', 'nt_hanoi_th', 'nt_hanoi_dc', 'nt_hanoi_gt', 'nt_hanoi_dh', 'nt_hanoi_rg');
    map.setCenter(new OpenLayers.LonLat(111.84197918135, 21.027580898957), 20);
    map.zoomToScale(400000, true);
    map.zoomIn();
    d.clearCookie();   
}

function mapHaiDuong() {
    if (map != null) {
        map.destroy();
    }
    id_place = d.getSelected();
    setContentTable(id_place);
    document.getElementById('lienkute').innerText = "Bảng địa điểm tỉnh Hải Dương";
    init('Hải Dương', 'HaiDuong_rg', 'nt_HaiDuong_th', 'nt_HaiDuong_dc', 'nt_HaiDuong_gt', 'nt_HaiDuong_dh', 'nt_HaiDuong_rg');
    map.setCenter(new OpenLayers.LonLat(111.84597316869, 20.887505215363), 20);
    map.zoomToScale(400000, true);
    map.zoomIn();
    d.clearCookie();
    
}

function mapBacNinh() {
    if (map != null) {
        map.destroy();
    }
    id_place = d.getSelected();
    setContentTable(id_place);
    document.getElementById('lienkute').innerText = "Bảng địa điểm tỉnh Bắc Ninh";
    init('Bắc Ninh', 'BacNinh_rg', 'nt_BacNinh_th', 'nt_BacNinh_dc', 'nt_BacNinh_gt', 'nt_BacNinh_dh', 'nt_BacNinh_rg');
    map.setCenter(new OpenLayers.LonLat(111.61045375951, 21.112038296418), 20);
    map.zoomToScale(400000, true);
    map.zoomIn();
    d.clearCookie();
}
//ham nay duoc goi khi load trang thi se load het du lieu
function setActiveShopMap(sum_place) {
    $.ajax({
        type: "POST",
        url: "Default.aspx/getCountRowPlaceId",
        contentType: "application/json; charset=utf-8",
        data: "{sum_place_id: '" + sum_place + "'}",
        dataType: "json",
        success: function (response) {
            var shops = response.d;
            var _id_place = 0;
            $.each(shops, function (index, active) {
                _id_place++;
                d.setNameNode(_id_place,active);
            });
        },
        error: AjaxFailed
    });
}

function setActiveShopmapId(_id_place, _change) {
    d.setNameNode(_id_place, _change);
    document.getElementById('MainContent_b2').innerText = _change;
}

function coundtActiveShop() {
    var count = (document.getElementById('MainContent_a2').innerText);
    var count1 = Number(count) + 1;
    document.getElementById('MainContent_a2').innerText = count1;
}

function countNoneActiveShop() {
    var count = (document.getElementById('MainContent_c2').innerText);
    var count1 = Number(count) + 1;
    document.getElementById('MainContent_c2').innerText = count1;
}

function setContentTable(_id_place) {
    $.ajax({
        type: "POST",
        url: "Default.aspx/getCountActivePlaceId",
        contentType: "application/json; charset=utf-8",
        data: "{_id_place_active: '" + _id_place + "'}",
        dataType: "json",
        success: function (response) {
            var shops = response.d;
                document.getElementById('MainContent_b2').innerText = shops[0];
                document.getElementById('MainContent_c2').innerText = shops[1];
                document.getElementById('MainContent_a2').innerText = shops[2];
        },
        error: AjaxFailed
    });
   // alert(_id_place);
}
